//
//  TabbarController.m
//  LightControl
//
//  Created by CKF on 2025/8/1.
//

#import "TabbarController.h"
#import "HomeViewController.h"
#import "SettingViewController.h"
@interface TabbarController ()

@end

@implementation TabbarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // 创建首页视图控制器
    HomeViewController *homeVC = [[HomeViewController alloc] init];
    // 设置首页 tabbar 项的标题、选中和未选中图片
    homeVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:LocalString(@"主页")
                                                      image:[UIImage imageNamed:@"home_n"]
                                              selectedImage:[UIImage imageNamed:@"home_s"]];
    
    // 创建设置视图控制器
    SettingViewController *settingsVC = [[SettingViewController alloc] init];
    // 设置设置页 tabbar 项的标题、选中和未选中图片
    settingsVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:LocalString(@"设置")
                                                          image:[UIImage imageNamed:@"setting_n"]
                                                  selectedImage:[UIImage imageNamed:@"setting_s"]];
    UINavigationController *homeNavi = [[UINavigationController alloc]initWithRootViewController:homeVC];
    UINavigationController *settingNavi = [[UINavigationController alloc]initWithRootViewController:settingsVC];
    // 创建 UITabBarController
    self.viewControllers = @[homeNavi, settingNavi];
    self.selectedIndex = 0 ;
    
    // 设置 tabbar 文字选中颜色为蓝色
    if (@available(iOS 13.0, *)) {
        UITabBarAppearance *appearance = [[UITabBarAppearance alloc] init];
        appearance.stackedLayoutAppearance.normal.titleTextAttributes = @{NSForegroundColorAttributeName: RGB(102, 103, 108)};
        appearance.stackedLayoutAppearance.selected.titleTextAttributes = @{NSForegroundColorAttributeName: RGB(00, 139, 233)};
        self.tabBar.standardAppearance = appearance;
        if (@available(iOS 15.0, *)) {
            self.tabBar.scrollEdgeAppearance = appearance;
        }
    } else {
        // 兼容旧版本 iOS
        [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: RGB(102, 103, 108)}
                                                 forState:UIControlStateNormal];
        [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: RGB(00, 139, 233)}
                                                 forState:UIControlStateSelected];
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
